<template>
	<view class="con">
		<!-- <view class="dd">
			<view class="dd__label">
				订单号
			</view>
			<input type="text" v-model="form.order_sn" class="dd__inp" placeholder="请输入购买订单号" />

		</view> -->
		<view class="dd">
			<view class="dd__label">
				下单手机号
			</view>
			<input type="number" maxlength="11" v-model="form.phone" class="dd__inp" placeholder="请输入下单手机号" />
		
		</view>
		<textarea v-model="form.address" placeholder="请粘贴领取的地址..." class="addr"></textarea>
		<!-- <view class="title" style="margin-bottom: 30rpx;">
			<view class="title__line">

			</view>
			上传购买图片<text style="color: #9A9898;font-size: 24rpx;">(可多张)</text>
		</view>
		<u-upload width="206rpx" height="206rpx" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic"
			name="1" multiple :maxCount="10">
			<image src="/static/up.png" class="up" mode=""></image>
		</u-upload> -->

		<view class="footer">
			<view class="footer__btn" @click="clicksub">
				确认提交
			</view>
		</view>
	</view>
</template>

<script>
	import {addCircleList} from '@/api/home.js'
	export default {
		data() {
			return {
				fileList1: [],
				form:{
					address:'',
					// order_sn:'',
					phone:''
				}
			};
		},
		methods: {
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://dan.fuliaoxx.com/api/common/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data)
							}, 1000)
						}
					});
				})
			},
			clicksub(){
				
				let urls=[]
				this.fileList1.map(t=>{
					urls.push(JSON.parse(t.url).data.url)
				})
				// console.log()
				this.form.images=urls.join(',')
				// if(!this.form.order_sn){
				// 	uni.showToast({
				// 		title:'请输入购买订单号',
				// 		icon:'error'
				// 	})
				// 	return
				// }
				if(!this.form.address){
					uni.showToast({
						title:'请粘贴领取的地址',
						icon:'error'
					})
					return
				}
				if(!this.form.phone){
					uni.showToast({
						title:'请输入下单手机号',
						icon:'error'
					})
					return
				}
				// if(!this.form.images){
				// 	uni.showToast({
				// 		title:'请上传购买图片',
				// 		icon:'error'
				// 	})
				// 	return
				// }
				uni.showLoading({
					title:'正在提交'
				})
				addCircleList(this.form).then(res=>{
					if(res.data.code==1){
						uni.showToast({
							title:'提交成功',
							icon:'success'
						})
						setTimeout(() => {
							uni.hideLoading()
							uni.navigateBack()
						}, 1000)
					}else{
						uni.showToast({
							title:'提交失败',
							icon:'error'
						})
					}
				})
			}
		},
	}
</script>

<style lang="scss">
	.con {
		border-top: 2rpx solid #F0EEEE;
		padding: 5rpx 30rpx;

		.dd {
			height: 100rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 2rpx solid #F9F9F9;

			&__label {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #6D6D6D;
				line-height: 26rpx;
			}

			&__inp {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #333;
				line-height: 38rpx;
				text-align: right;

				.uni-input-placeholder {
					color: #6d6d6d !important;
				}
			}
		}
	}

	.addr {
		width: 100%;
		height: 200rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #333;
		padding-top: 30rpx;
		border-bottom: 2rpx solid #F9F9F9;

		.uni-textarea-placeholder {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #6D6D6D;
		}
	}

	.title {
		display: flex;
		align-items: center;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 26rpx;
		color: #1E1E1E;
		line-height: 26rpx;

		&__line {
			width: 5rpx;
			height: 24rpx;
			background: #3262FD;
			margin-right: 10rpx;
		}
	}

	.up {
		width: 206rpx;
		height: 206rpx;
		
	}

	.footer {
		padding: 70rpx 60rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: center;

		&__btn {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 628rpx;
			height: 94rpx;
			background: #3262FD;
			border-radius: 15rpx;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 32rpx;
		}

	}
</style>